package com.ibeeking.found.open.api.feign.fallback;

import com.ibeeking.found.common.entity.KeyValue;
import com.ibeeking.found.open.api.common.dto.CampaignDivideScaleDTO;
import com.ibeeking.found.open.api.common.dto.CampaignListDTO;
import com.ibeeking.found.open.api.common.dto.CampaignStatisticsDTO;
import com.ibeeking.found.open.api.common.dto.ConfirmOrderCouponDTO;
import com.ibeeking.found.open.api.common.dto.CouponGoodsDTO;
import com.ibeeking.found.open.api.common.dto.MemberCouponInfoDTO;
import com.ibeeking.found.open.api.common.dto.MemberCouponListDTO;
import com.ibeeking.found.open.api.common.dto.MemberCouponQRDTO;
import com.ibeeking.found.open.api.common.param.CouponVerificationParam;
import com.ibeeking.found.open.api.common.param.CouponVerificationQRParam;
import com.ibeeking.found.open.api.common.param.ModifyCouponStatusParam;
import com.ibeeking.found.open.api.common.query.CampaignPageQuery;
import com.ibeeking.found.open.api.common.query.CampaignStatisticsQuery;
import com.ibeeking.found.open.api.common.query.ConfirmOrderCouponQuery;
import com.ibeeking.found.open.api.common.query.CouponGoodsQuery;
import com.ibeeking.found.open.api.common.query.ShareScaleQuery;
import com.ibeeking.found.open.api.common.query.ShopMemberCouponPageQuery;
import com.ibeeking.found.open.api.feign.MarketingFeignClient;
import com.ibeeking.nematos.utils.base.page.Page;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
@Slf4j
public class MarketingFeignFallbackFactory implements FallbackFactory<MarketingFeignClient> {
    @Override
    public MarketingFeignClient create(Throwable throwable) {
        log.error("Open服务调用MarketingC服务异常", throwable);
        return new MarketingFeignClient() {

            @Override
            public ResponseResult<Page<MemberCouponListDTO>> shopMemberCouponList(ShopMemberCouponPageQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询会员指定店铺券列表失败。", new Page<>());
            }

            @Override
            public ResponseResult<List<KeyValue<Integer, String>>> queryCouponTypes() {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询券类型列表失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<KeyValue<Integer, String>>> queryVerificationChannel() {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询券核销渠道列表失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<MemberCouponInfoDTO> queryCouponInfoByCouponCode(Long couponCode) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据券码查询券信息失败。", null);
            }

            @Override
            public ResponseResult<Boolean> lockCoupon(ModifyCouponStatusParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，锁券失败。", false);
            }

            @Override
            public ResponseResult<Boolean> unLockCoupon(ModifyCouponStatusParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，解锁券失败。", false);
            }

            @Override
            public ResponseResult<Boolean> verificationCoupon(List<CouponVerificationParam> params) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，核销券失败。", false);
            }

            @Override
            public ResponseResult<Boolean> verificationCouponByQr(CouponVerificationQRParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "通过扫码核销券失败。", false);
            }

            @Override
            public ResponseResult<MemberCouponQRDTO> queryCouponCodeByQRCode(String qrCode) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，扫码查询券信息失败。", null);
            }

            @Override
            public ResponseResult<ConfirmOrderCouponDTO> confirmOrderCoupon(ConfirmOrderCouponQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，选券失败。", null);
            }

            @Override
            public ResponseResult<Page<CampaignListDTO>> campaignList(CampaignPageQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询活动列表失败。", new Page<>());
            }

            @Override
            public ResponseResult<CampaignStatisticsDTO> campaignStatistics(CampaignStatisticsQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询活动统计失败。", null);
            }

            @Override
            public ResponseResult<List<CampaignDivideScaleDTO>> campaignDivide(ShareScaleQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询活动分摊失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<CouponGoodsDTO>> queryCouponGoodsRelation(CouponGoodsQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询券码和商品关系失败。", Collections3.emptyList());
            }
        };
    }
}
